﻿using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using Pomelo.EntityFrameworkCore.MySql.Scaffolding.Internal;
using ZGL.Api.Entity;

namespace ZGL.Api.Data;

public partial class DataContext : DbContext
{
    public DataContext()
    {
    }

    public DataContext(DbContextOptions<DataContext> options)
        : base(options)
    {
    }

    public virtual DbSet<IdRule> IdRules { get; set; }

    public virtual DbSet<IdValue> IdValues { get; set; }

    public virtual DbSet<SysMenuAuthority> SysMenuAuthorities { get; set; }

    public virtual DbSet<SysRole> SysRoles { get; set; }

    public virtual DbSet<SysRoleDataAuth> SysRoleDataAuths { get; set; }

    public virtual DbSet<SysRoleMenuAuth> SysRoleMenuAuths { get; set; }

    public virtual DbSet<SysUser> SysUsers { get; set; }

    public virtual DbSet<SysUserOrgRelation> SysUserOrgRelations { get; set; }

    public virtual DbSet<SysUserRoleRelation> SysUserRoleRelations { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.
        => optionsBuilder.UseMySql("server=118.89.133.25;database=mysqls;user id=SA;password=mysql", Microsoft.EntityFrameworkCore.ServerVersion.Parse("5.6.51-mysql"));

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder
            .UseCollation("utf8_general_ci")
            .HasCharSet("utf8");

        modelBuilder.Entity<IdRule>(entity =>
        {
            entity.HasKey(e => e.IdName).HasName("PRIMARY");

            entity.ToTable("id_rule", tb => tb.HasComment("编号规则定义"));

            entity.Property(e => e.IdName)
                .HasMaxLength(32)
                .HasComment("标识")
                .HasColumnName("id_name");
            entity.Property(e => e.CreateAt)
                .HasDefaultValueSql("CURRENT_TIMESTAMP")
                .HasComment("建立时间")
                .HasColumnType("timestamp")
                .HasColumnName("create_at");
            entity.Property(e => e.IdDesc)
                .HasMaxLength(128)
                .HasDefaultValueSql("''")
                .HasComment("标识说明")
                .HasColumnName("id_desc");
            entity.Property(e => e.IdExpress)
                .HasMaxLength(128)
                .HasDefaultValueSql("''")
                .HasComment("编号生成规则")
                .HasColumnName("id_express");
            entity.Property(e => e.IdType)
                .HasMaxLength(128)
                .HasDefaultValueSql("''")
                .HasComment("序号类型 终身序号/日序号/月序号")
                .HasColumnName("id_type");
            entity.Property(e => e.SeqType)
                .HasMaxLength(128)
                .HasDefaultValueSql("''")
                .HasComment("序号规则")
                .HasColumnName("seq_type");
            entity.Property(e => e.UpdateAt)
                .ValueGeneratedOnAddOrUpdate()
                .HasDefaultValueSql("CURRENT_TIMESTAMP")
                .HasComment("更新日期")
                .HasColumnType("timestamp")
                .HasColumnName("update_at");
        });

        modelBuilder.Entity<IdValue>(entity =>
        {
            entity.HasKey(e => e.IdCode).HasName("PRIMARY");

            entity.ToTable("id_value", tb => tb.HasComment("编号规则值"));

            entity.Property(e => e.IdCode)
                .HasMaxLength(50)
                .HasComment("标识")
                .HasColumnName("id_code");
            entity.Property(e => e.CreateAt)
                .HasDefaultValueSql("CURRENT_TIMESTAMP")
                .HasComment("建立时间")
                .HasColumnType("timestamp")
                .HasColumnName("create_at");
            entity.Property(e => e.CurrentValue)
                .HasDefaultValueSql("'1'")
                .HasComment("当前值")
                .HasColumnType("bigint(20)")
                .HasColumnName("current_value");
            entity.Property(e => e.UpdateAt)
                .ValueGeneratedOnAddOrUpdate()
                .HasDefaultValueSql("CURRENT_TIMESTAMP")
                .HasComment("更新日期")
                .HasColumnType("timestamp")
                .HasColumnName("update_at");
        });

        modelBuilder.Entity<SysMenuAuthority>(entity =>
        {
            entity.HasKey(e => e.MenuAuthId).HasName("PRIMARY");

            entity.ToTable("sys_menu_authority");

            entity.Property(e => e.MenuAuthId)
                .HasColumnType("bigint(255)")
                .HasColumnName("menu_auth_id");
            entity.Property(e => e.AuthCode)
                .HasMaxLength(255)
                .HasColumnName("auth_code");
            entity.Property(e => e.CreateBy)
                .HasMaxLength(255)
                .HasColumnName("create_by");
            entity.Property(e => e.CreateTime)
                .HasColumnType("timestamp")
                .HasColumnName("create_time");
            entity.Property(e => e.Hidden)
                .HasMaxLength(255)
                .HasColumnName("hidden");
            entity.Property(e => e.Icon)
                .HasMaxLength(255)
                .HasColumnName("icon");
            entity.Property(e => e.MenuName)
                .HasMaxLength(255)
                .HasColumnName("menu_name");
            entity.Property(e => e.PageName)
                .HasMaxLength(255)
                .HasColumnName("page_name");
            entity.Property(e => e.ParentId)
                .HasColumnType("bigint(255)")
                .HasColumnName("parent_id");
            entity.Property(e => e.Sort)
                .HasMaxLength(255)
                .HasColumnName("sort");
            entity.Property(e => e.Status)
                .HasMaxLength(255)
                .HasColumnName("status");
            entity.Property(e => e.Type)
                .HasMaxLength(255)
                .HasColumnName("type");
            entity.Property(e => e.UpdateBy)
                .HasMaxLength(255)
                .HasColumnName("update_by");
            entity.Property(e => e.UpdateTime)
                .HasColumnType("timestamp")
                .HasColumnName("update_time");
            entity.Property(e => e.UrlPath)
                .HasMaxLength(255)
                .HasColumnName("url_path");
        });

        modelBuilder.Entity<SysRole>(entity =>
        {
            entity.HasKey(e => e.RoleId).HasName("PRIMARY");

            entity.ToTable("sys_role");

            entity.Property(e => e.RoleId)
                .HasColumnType("bigint(255)")
                .HasColumnName("role_id");
            entity.Property(e => e.CorpId)
                .HasColumnType("bigint(255)")
                .HasColumnName("corp_id");
            entity.Property(e => e.CreateBy)
                .HasColumnType("bigint(255)")
                .HasColumnName("create_by");
            entity.Property(e => e.CreateTime)
                .HasColumnType("timestamp")
                .HasColumnName("create_time");
            entity.Property(e => e.RoleDesc)
                .HasMaxLength(255)
                .HasColumnName("role_desc");
            entity.Property(e => e.RoleName)
                .HasMaxLength(255)
                .HasColumnName("role_name");
            entity.Property(e => e.RoleType)
                .HasMaxLength(255)
                .HasColumnName("role_type");
            entity.Property(e => e.Status)
                .HasMaxLength(255)
                .HasColumnName("status");
            entity.Property(e => e.UpdateTime)
                .HasColumnType("timestamp")
                .HasColumnName("update_time");
        });

        modelBuilder.Entity<SysRoleDataAuth>(entity =>
        {
            entity.HasKey(e => e.RoleId).HasName("PRIMARY");

            entity.ToTable("sys_role_data_auth");

            entity.Property(e => e.RoleId)
                .HasColumnType("bigint(255)")
                .HasColumnName("role_id");
            entity.Property(e => e.CreateTime)
                .HasColumnType("timestamp")
                .HasColumnName("create_time");
            entity.Property(e => e.DataAuthId)
                .HasColumnType("bigint(255)")
                .HasColumnName("data_auth_id");
            entity.Property(e => e.UpdateTime)
                .HasColumnType("timestamp")
                .HasColumnName("update_time");
        });

        modelBuilder.Entity<SysRoleMenuAuth>(entity =>
        {
            entity
                .HasNoKey()
                .ToTable("sys_role_menu_auth");

            entity.HasKey(e => e.RoleId).HasName("PRIMARY");
            entity.HasKey(e => e.MenuAuthId).HasName("PRIMARY");
            entity.Property(e => e.CreateBy)
                .HasColumnType("bigint(20)")
                .HasColumnName("create_by");
            entity.Property(e => e.CreateTime)
                .HasColumnType("timestamp")
                .HasColumnName("create_time");
            entity.Property(e => e.MenuAuthId)
                .HasColumnType("bigint(20)")
                .HasColumnName("menu_auth_id");
            entity.Property(e => e.RoleId)
                .HasColumnType("bigint(20)")
                .HasColumnName("role_id");
            entity.Property(e => e.UpdateTime)
                .HasColumnType("timestamp")
                .HasColumnName("update_time");
        });

        modelBuilder.Entity<SysUser>(entity =>
        {
            entity.HasKey(e => e.UserId).HasName("PRIMARY");

            entity.ToTable("sys_user");

            entity.Property(e => e.UserId)
                .HasColumnType("bigint(20)")
                .HasColumnName("user_id");
            entity.Property(e => e.CorpId)
                .HasColumnType("bigint(20) unsigned zerofill")
                .HasColumnName("corp_id");
            entity.Property(e => e.CreateTime)
                .HasColumnType("timestamp")
                .HasColumnName("create_time");
            entity.Property(e => e.JobNum)
                .HasMaxLength(255)
                .HasColumnName("job_num");
            entity.Property(e => e.Openid)
                .HasMaxLength(255)
                .HasColumnName("openid");
            entity.Property(e => e.Password)
                .HasMaxLength(255)
                .HasColumnName("password");
            entity.Property(e => e.PhotoUrl)
                .HasMaxLength(255)
                .HasColumnName("photo_url");
            entity.Property(e => e.Realname)
                .HasMaxLength(255)
                .HasColumnName("realname");
            entity.Property(e => e.Station)
                .HasMaxLength(255)
                .HasColumnName("station");
            entity.Property(e => e.Telephone)
                .HasMaxLength(255)
                .HasColumnName("telephone");
            entity.Property(e => e.UpdateTime)
                .HasColumnType("timestamp")
                .HasColumnName("update_time");
            entity.Property(e => e.Username)
                .HasMaxLength(255)
                .HasColumnName("username");
        });

        modelBuilder.Entity<SysUserOrgRelation>(entity =>
        {
            entity.HasKey(e => e.UserId).HasName("PRIMARY");

            entity.ToTable("sys_user_org_relation");

            entity.Property(e => e.UserId)
                .ValueGeneratedNever()
                .HasColumnType("bigint(20)")
                .HasColumnName("user_id");
            entity.Property(e => e.CreateTime)
                .HasColumnType("timestamp")
                .HasColumnName("create_time");
            entity.Property(e => e.OrgId)
                .HasColumnType("bigint(20)")
                .HasColumnName("org_id");
            entity.Property(e => e.UpdateTime)
                .HasColumnType("timestamp")
                .HasColumnName("update_time");
        });

        modelBuilder.Entity<SysUserRoleRelation>(entity =>
        {
            entity.HasKey(e => e.UserId).HasName("PRIMARY");
            entity.HasKey(e => e.RoleId).HasName("PRIMARY");
            entity.ToTable("sys_user_role_relation");

            entity.Property(e => e.UserId)
                .HasColumnType("bigint(20)")
                .HasColumnName("user_id");
            entity.Property(e => e.CreateTime)
                .HasColumnType("timestamp")
                .HasColumnName("create_time");
            entity.Property(e => e.RoleId)
                .HasColumnType("bigint(20)")
                .HasColumnName("role_id");
            entity.Property(e => e.UpdateTime)
                .HasColumnType("timestamp")
                .HasColumnName("update_time");
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
